<template>
<div class="pb50">
    <el-form ref="form" size="small" :model="form" label-width="200px">
      <div class="common-form">{{$t('user.withdrawal_settings')}}</div>

      <el-form-item :label="$t('user.withdrawal_method')" v-if="list.length > 0">
        <el-checkbox-group v-model="form.payType">
          <el-checkbox
            v-for="(item, index) in list"
            :label="item.value"
            :key="index"
            >{{item.name}}</el-checkbox
          >
        </el-checkbox-group>
        <div class="tips"> {{$t('user.wechat_payment_note')}} 

</div>
        <div class="tips">{{$t('user.alipay_payment_note')}}</div>
      </el-form-item>

      <el-form-item :label="$t('user.enable_withdrawal')">
        <el-radio-group v-model="form.isOpen">
          <el-radio label="1">{{$t('user.enabled')}}</el-radio>
          <el-radio label="0">{{$t('user.disabled')}}</el-radio>
        </el-radio-group>
        <div class="lh18 mt10 gray9">
          <p>{{$t('user.enable_withdrawal_note')}}</p>
        </div>
      </el-form-item>
      <el-form-item
        :label="$t('user.withdrawal_ratio')"
        prop="cashRatio"
        :rules="[{  required: true,  message: ' '}]"
      >
        <el-input
          :placeholder="$t('user.input_content')"
          v-model="form.cashRatio"
          class="max-w460"
        >
          <template #append>%</template>
        </el-input>
        <div class="lh18 mt10 gray9">
          <p>{{$t('user.withdrawal_ratio_note')}}</p>
          <p>{{$t('user.withdrawal_ratio_example')}}</p>
        </div>
      </el-form-item>
      <el-form-item
        :label="$t('user.min_withdrawal_amount')"
        prop="minMoney"
        :rules="[{  required: true,  message: ' '}]"
      >
        <el-input
          :placeholder="$t('user.input_content')"
          v-model="form.minMoney"
          class="max-w460"
        >
          <template #append>{{$t('user.currency_yuan')}}</template>
        </el-input>
        <div class="lh18 mt10 gray9">
          <p>{{$t('user.min_withdrawal_note')}}</p>
        </div>
      </el-form-item>
      <!--提交-->
      <div class="common-button-wrapper">
        <el-button
          type="primary"
          size="small"
          @click="onSubmit"
          :loading="loading"
          >{{$t('user.submit')}}</el-button
        >
      </div>
    </el-form>
  </div>
</template>

<script>
import BalanceApi from "@/api/balance.js";
export default {
  data() {
    return {
      form: {},
      list: [],
      loading: false
    };
  },
  created() {
    /*获取数据*/
    this.getData();
  },
  methods: {
    /*获取数据*/
    getData() {
      let self = this;
      let Params = {};
      BalanceApi.getCashSetting(Params, true).then(res => {
        self.form = res.data.balance;
        self.list = res.data.payType;
      }).catch(error => {});
    },
    /*保存*/
    onSubmit() {
      let self = this;
      let form = self.form;
      self.$refs.form.validate(valid => {
        if (valid) {
          self.loading = true;
          BalanceApi.cashSetting(form, true).then(data => {
            self.loading = false;
            if (data.code == 1) {
              ElMessage({
                message: $t("user.save_success"),
                type: "success"
              });
            } else {
              self.loading = false;
            }
          }).catch(error => {
            self.loading = false;
          });
        }
      });
    }
  }
};
</script>

